package com.ojoin.trade.common.web.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.TbUploadFileDao;
import com.ojoin.trade.common.web.domain.TbUploadFile;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 15-10-26
 * Time: 上午11:24
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class TbUploadFileDaoImpl extends BaseDaoImpl<TbUploadFile> implements TbUploadFileDao {


	@Override
	public int updateStatusById(int id, String status)
			throws BusinessException {
		String mapMethodName = "updateStatusById";
        try { 
        	HashMap<String, Object> paramMap = new HashMap<String, Object>();
        	paramMap.put("id", id);
        	paramMap.put("status", status);
        	
            return this.sqlSessionTemplate.update(getSqlName(mapMethodName), paramMap);
        } catch (Exception e) {
            throw new DaoException(String.format("更新上传记录的状态出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
	}

	@Override
	public List<TbUploadFile> queryUnCommitAfter(Date time) throws BusinessException {
		String mapMethodName = "selectUnCommitAfter";
        try { 
        	HashMap<String, Object> paramMap = new HashMap<String, Object>();
        	paramMap.put("rowCreateTime", time);
            return this.sqlSessionTemplate.selectList(getSqlName(mapMethodName), paramMap);
        } catch (Exception e) {
            throw new DaoException(String.format("查询一段时间后未提交的上传文件出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
	}

	@Override
	public int updateFileTypeAndStatusById(int id, String status,
			String filetype) throws BusinessException {
		String mapMethodName = "updateFileTypeAndStatusById";
        try { 
        	HashMap<String, Object> paramMap = new HashMap<String, Object>();
        	paramMap.put("id", id);
        	paramMap.put("status", status);
        	paramMap.put("filetype", filetype);
        	
            return this.sqlSessionTemplate.update(getSqlName(mapMethodName), paramMap);
        } catch (Exception e) {
            throw new DaoException(String.format("更新上传记录的状态和文件类型出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
	}

	@Override
	public List<TbUploadFile> getFileListByCondition(Integer joinuserid, String filetype, String platformtype, String startdate,
			String enddate,Pageable page) throws BusinessException {
		String mapMethodName = "getFileListByCondition";
        try { 
        	HashMap<String, Object> paramMap = new HashMap<String, Object>();
        	paramMap.put("joinuserid", joinuserid);
        	paramMap.put("filetype", filetype);
        	paramMap.put("platformtype", platformtype);
        	paramMap.put("startdate", startdate);
        	paramMap.put("enddate", enddate);
            return this.sqlSessionTemplate.selectList(getSqlName(mapMethodName), paramMap,getPageBounds(page));
        } catch (Exception e) {
            throw new DaoException(String.format("根据条件查询上传文件出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
		
	}
 
}
